package com.arrogames.rgblabyrinth.game.graphics {
	
	import com.arrogames.tmx.CoordinateUtil;
	
	import flash.geom.Point;
	
	import starling.display.Sprite;
	
	public class GridBorderLayer extends Sprite {
		
		public function GridBorderLayer() {
			super();
			this.width = 800;
		}
		
		/**
		 * drawGrid 
		 * 
		 * @param	tileWidth	int		the width of one tile
		 * @param	tileHeight	int		the height of one tile
		 * @param	rows		int		the number of rows
		 * @param	cols		int		the number of columns
		 */
		public function drawGrid(tileWidth:int, tileHeight:int, rows:int, cols:int):void {
			//start coordinate
			/*what we need to do here, to draw the grid exactly as the isometric screen is layed out is:
				for each row: 
					get the starting point (iso (current row, 0) )
					get the ending point (iso ( current row, max cols )
					draw line from start to end point
				for each column:
					get the starting point	(iso (0, current col) )
					get the ending point    (iso (max rows, current col) )
					draw line from start to end point
			*/
			var start:Point = null;
			var end:Point = null;
			//draw the rows
			for ( var currentRow:int = 0; currentRow <= rows; currentRow++)  {
				start = CoordinateUtil.isometricToScreen(currentRow, 0, tileWidth, tileHeight);
				end = CoordinateUtil.isometricToScreen(currentRow, cols, tileWidth, tileHeight);
				drawLine(start, end);
			}
			//draw the columns
			for ( var currentCol:int = 0; currentCol <= cols; currentCol++) {
				start = CoordinateUtil.isometricToScreen(0, currentCol, tileWidth, tileHeight);
				end = CoordinateUtil.isometricToScreen(rows, currentCol, tileWidth, tileHeight);
				drawLine(start, end);
			}
		}
		
		protected function drawLine(from:Point, to:Point) : void {
			var line:Line = new Line(0xFFFFFF, from.x, from.y, to.x, to.y);
			addChild(line);
		}
		
	}
}